<?php 
class SiteController extends Controller {
	/**
	 * Declares class-based actions.
	 */
	public function actions() {
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha' => array(
				'class' => 'CCaptchaAction',
				'backColor' => 0xFFFFFF
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page' => array(
				'class' => 'CViewAction'
			)
		);
	}
	
	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionIndex() {
		$this->redirect('admin/dashboard');
		// $this->render('index', array(
		// ));
	}
	
	/**
	 * This is the action to handle external exceptions.
	 */
	public function actionError() {
		$this->layout = '/layouts/1col';
		if ($error = Yii::app()->errorHandler->error) {
			if (Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}
	
	/**
	 * Display post edit dialog
	 */
	public function actionPage($name) {
		$model = Page::model()->findByAttributes(array('name'=>$name));
		if (!$model)
			throw new CHttpException(404, 'The requested page could not be found');
			
		$this->render('page', array(
			'model' => $model
		));
	}
}